import Flutter
import UIKit
import StoreKit
//import AdSupport
//import AppTrackingTransparency

@main
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    
//    requestIDFA()
   registerPlugin(messenger: window?.rootViewController as! FlutterBinaryMessenger)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
    
  func registerPlugin(messenger:FlutterBinaryMessenger) {
      let channel = FlutterMethodChannel(name:"bitcoin.flutter.dev/channel",binaryMessenger: messenger)
      channel.setMethodCallHandler { (call:FlutterMethodCall, result:@escaping FlutterResult) in
          if(call.method == "toMarket"){
              //跳转应用商店
              self.toMarket()
              result(true)
          }
      }
  }
    
  func toMarket(){
        
      if #available(iOS 10.3, *){
          SKStoreReviewController.requestReview()
      }else{
          let url = URL(string:"itms-apps://itunes.apple.com/app/id1573244280")
          if(!UIApplication.shared.canOpenURL(url!)){
              return
          }
          if #available(iOS 10.0, *){
              UIApplication.shared.open(url!,options: [:]){ (success) in

              }
          }else{
              let success = UIApplication.shared.openURL(url!)
          }
      }
      
  }
    
//    func requestIDFA(){
//        if #available(iOS 14, *){
//            ATTrackingManager.requestTrackingAuthorization{
//                status in
//                switch status {
//                case .authorized:
//                    self.getIDFA()
//                @unknown default:
//                    print("状态=\(status)")
//                }
//            }
//        }
//    }
//    
//    func getIDFA(){
//        let idfa = ASIdentifierManager.shared().advertisingIdentifier.uuidString
//        print("idfa === \(idfa)")
//    }
}
